﻿using Digitalmes.Domain;
using Digitalmes.Domain.Mes;
using Digitalmes.Scada.Models;
using Digitalmes.Sugar;

namespace Digitalmes.Scada.Services.Impl;

/// <summary>
/// 上件请求服务
/// </summary>
internal sealed class ReqService : IReqService, ITransientDependency
{
    private readonly SugarRepository<ProdTransSn> _transSnRepo;

    public ReqService(SugarRepository<ProdTransSn> transSnRepo)
    {
        _transSnRepo = transSnRepo;
    }

    public async Task<HandleResult> ReqAsync(ReqInput input)
    {
        // 检测产品是否已做过
        var isDone = await _transSnRepo.IsAnyAsync(s => s.Sn == input.SN || s.CustomerSn == input.SN);
        if (isDone)
        {
            return HandleResult.Error(ErrCode.E1003);
        }

        // 校验码规则是否 OK

        return HandleResult.Ok();
    }
}
